//
//  EZCDBTableInfo.cpp
//  zhaitu
//
//  Created by ellzu on 13-8-1.
//  Copyright (c) 2013年 ellzu. All rights reserved.
//

#include "EZCDBTableInfo.h"

using namespace EZCDBNS;

EZCDBTableInfo::EZCDBTableInfo():
insertSql("")
{
    
}
EZCDBTableInfo::~EZCDBTableInfo()
{
    for (int i=0; i<tableFilds.size(); i++) {
        EZCDBFieldInfo *fieldInfo = tableFilds.at(i);
        fieldInfo->Release();
    }
    std::cout << "~EZCDBTableInfo" <<std::endl;
}

std::string EZCDBTableInfo::getInsertSql()
{
    if (insertSql.length()>0) {
        return insertSql;
    }
    
    insertSql = std::string("insert or replace into ");
    std::string valueSql("values(");
    insertSql += this->tableName;
    insertSql += "(";
    for (int i=0; i<this->tableFilds.size(); i++) {
        EZCDBFieldInfo *fieldInfo = this->tableFilds.at(i);
        
        insertSql += fieldInfo->dbFieldName;
        
        if (i==this->tableFilds.size()-1) {
            insertSql += ") ";
            valueSql += "?);";
        }else{
            insertSql += ",";
            valueSql += "?,";
        }
    }
    insertSql += valueSql;

    return insertSql;
}